public class Leetcode2000 {
    public static void main(String[] args) {
        System.out.println(reversePrefix("abcd", 'z'));
    }

    public static String reversePrefix(String word, char ch) {
        StringBuilder res = new StringBuilder();
        char[] words = word.toCharArray();
        boolean flag = true;

        for (char c : words) {
            res.append(c);
            if (c == ch && flag) {
                res.reverse();
                flag = false;
            }
        }

        return res.toString();
    }

}
